package com.aotain.oframework.dao.sqlt;

import java.io.Serializable;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;

import com.aotain.oframework.dto.PageDTO;

public interface JpaSqltRepository<T, ID extends Serializable> extends
		JpaRepository<T, ID> {

	/**
	 * to retrieve JPQL from pre-defined sqlt.xml file.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @return parsed jpql string.
	 */
	public String getJpqlTemplate(String namespace, String sqltId,
			Object criteria);

	/**
	 * to retrieve Native SQL from pre-defined sqlt.xml file.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @return parsed native sql string.
	 */
	public String getNativeSqlTemplate(String namespace, String sqltId,
			Object criteria);

	/**
	 * return unique result from a pre-defined native sql string.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @return unique result
	 */
	public Object queryNativeSqlForObject(String namespace, String sqltId,
			Object criteria);

	/**
	 * return list result from a pre-defined native sql string.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @return list of persistence object
	 */
	public List queryNativeSqlForList(String namespace, String sqltId,
			Object criteria);

	/**
	 * return single page list result from a pre-defined native sql string.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @param pageable
	 *            - Spring data pagination object
	 * @return list of persistence object(in the form of object[])
	 */
	public List queryNativeSqlForPage(String namespace, String sqltId,
			Object criteria, Pageable pageable);

	public List queryNativeSqlForSortPage(String namespace, String sqltId,
			PageDTO pageDTO);

	public List queryNativeSqlForSortPage(String namespace, String sqltId,
			Object[] criteria, PageDTO pageDTO);

	public Integer queryNativeSqlForObjsCount(String namespace, String sqltId,
			Object[] criteria);

	/**
	 * return unique result from a pre-defined jpql string.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @return unique result
	 */
	public Object queryJpqlForObject(String namespace, String sqltId,
			Object criteria);

	/**
	 * return list result from a pre-defined jpql string.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @return list of persistence object
	 */
	public List queryJpqlForList(String namespace, String sqltId,
			Object criteria);

	/**
	 * return single page list result from a pre-defined jpql string.
	 * 
	 * @param namespace
	 *            - the namespace of the template
	 * @param sqltId
	 *            - the sql template id
	 * @param criteria
	 *            - the criteria for parameter resolving
	 * @param pageable
	 *            - spring data pagination object
	 * @return list of persistence object
	 */
	public List queryJpqlForPage(String namespace, String sqltId,
			Object criteria, Pageable pageable);

	@SuppressWarnings("rawtypes")
	public List queryJpqlForPage2(String namespace, String sqltId,
			PageDTO pageDTO);

	public List queryJpqlForReceptionRecord(String namespace, String sqltId,
			PageDTO pageDTO);

	public List queryNativeSqlForList(String namespace, String sqltId,
			Object[] criteria);

	/**
	 * This method is for counting record in pagination.
	 * 
	 * @param namespace
	 * @param sqltId
	 * @param criteria
	 * @return
	 */
	public Integer queryJpqlRowCount(String namespace, String sqltId,
			Object criteria);

	/**
	 * This method is for counting record in pagination.
	 * 
	 * @param namespace
	 * @param sqltId
	 * @param criteria
	 * @return
	 */
	public Integer queryNativeSqlRowCount(String namespace, String sqltId,
			Object criteria);

	public List queryNativeSqlForList(String sql, Object criteria);

	public List queryNativeSqlForPage(String sql, Object criteria,
			PageDTO pageDTO);

	// public Long getMaxSeq(String modelName);

	// public Integer getSeqNumAndAutoAddOne(int caseKey);

	Object queryNativeSqlForObject(String sql, Object criteria);

	int queryNativeSql(String sql, Object criteria);

	int executeNativeSql(String namespace, String sqltId, Object criteria);

	// List<List<String>> getCaseLogDetail(String tableName,String auuid,String
	// buuid);

}
